<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="Bookmark" href="/favicon.ico">
		<link rel="Shortcut Icon" href="/favicon.ico" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
		<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
		<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
		<link rel="stylesheet" href="../lib/layui/css/layui.css">
		<link rel="stylesheet" href="../lib/zTree/v3/css/zTreeStyle/zTreeStyle.css">
		<style>

		</style>
		<title>授权信息</title>
	</head>

	<body>
		<div class="page-container">
			<ul id="myZtree" class="ztree"></ul>
			<div class="layui-form-item text-c">
				<button class="layui-btn" lay-submit="" lay-filter="btnSubmit">保存</button>
			</div>
		</div>
		<!--_footer 作为公共模版分离出去-->
		<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
		<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
		<script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
		<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
		<!--/_footer 作为公共模版分离出去-->
		<script type="text/javascript" src="../lib/layui/layui.js"></script>
		<script type="text/javascript" src="../lib/zTree/v3/js/jquery.ztree.all-3.5.js"></script>
		<script type="text/javascript" src="../static/js/common.js"></script>
		<!--请在下方写此页面业务相关的脚本-->
		<script type="text/javascript">
			var role_id = parent.$("#role_id").val();
			var myZtree;

			layui.use(['form'], function() {
				var form = layui.form;
				var zNodes;
				var setting = {
					async: {
						enable: true,
						url: admin_url + "/scaRolePermission/getZtreePerminssionAuthInfo",
						otherParam: {
							"token": token,
							"tokenUserId": userId,
							"roleId": role_id
						},
						dataFilter: filter
					},
					check: {　　　　
						enable: true,
						　　　　autoCheckTrigger: false,
						　　　　chkStyle: "checkbox",
						　　　　chkboxType: {
							"Y": "ps", //勾选影响上级，影响下级
							"N": "s" //取消影响下级，不影响上级
						}
					},
					data: {
						simpleData: {
							enable: true
						}
					},
					edit: {
						enable: false,
						editNameSelectAll: true,
					},
					view: {
						selectedMulti: false,
						nameIsHTML: false
					},
					callback: {
						beforeClick: function(treeId, treeNode, clickFlag) {
							return(treeNode.click != false);
						},
						onAsyncSuccess: zTreeOnAsyncSuccess
					}
				};
				myzTree = $.fn.zTree.init($("#myZtree"), setting, zNodes);
				//监听提交
				form.on('submit(btnSubmit)', function(e) {
					var data = {
						"permissionIds": getCheckedIds(),
						"token": token,
						"tokenUserId": userId,
						"roleId": role_id
					};
					request_ajax("POST", admin_url + "/scaRolePermission/oprPermissionRole", data, function(result) {
						layer.msg(result.msg, {
							time: 800,
							end: function() {
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index); //再执行关闭   
								parent.tableReload();
							}
						});
					});
					return false;
				});

			});

			function getCheckedIds() {
				var treeObj = $.fn.zTree.getZTreeObj("myZtree");
				var nodes = treeObj.getCheckedNodes(true);
				var ids = new Array();
				for(var i = 0; i < nodes.length; i++) {
					ids.push(nodes[i].id);
				}
				return ids.toString();
			}

			function filter(treeId, parentNode, childNodes) {
				return childNodes.data
			};

			function zTreeOnAsyncSuccess(event, treeId, treeNode) {
				var treeObj = $.fn.zTree.getZTreeObj("myZtree");
				treeObj.expandAll(true);
			};
		</script>
	</body>

</html>